<template>
    <div class="e-form">
        <BillTop title="配置计划变更新增" @cancel="handleClose"></BillTop>
        <div class="tabs">
            <div class="tabs-title">基本信息</div>
            <el-form ref="form" :model="formData.planConfiguration" :rules="rules" label-width="200px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="计划编号：" >
                            <span>{{ formData.planConfiguration.billNo}}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="变更日期：" >
                            <span>{{ formData.planConfiguration.billDate}}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="币种：">
                            <span>{{formData.planConfiguration.currency}}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="原长租计划金额（元）：">
                            <span>{{ formData.planConfiguration.longPlanAmount }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="变更后长租计划金额（元）：">
                            <span>{{ formData.planConfiguration.changeLongPlanAmount }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="原临租总金额（元）：" >
                            <span>{{ formData.planConfiguration.tempLeaseAmount }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="变更后临租总金额（元）："  prop="changeTempLeaseAmount">
                            <el-input
                                placeholder="请输入金额"
                                v-model="formData.planConfiguration.changeTempLeaseAmount"
                                v-enter-float="{
                                    set: formData,
                                    val: 'planConfiguration',
                                    key: 'changeTempLeaseAmount'
                                }"
                                clearable>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="原总计划金额（元）：" >
                            <span>{{ formData.planConfiguration.planAmount }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="变更后总计划金额（元）：" >
                            <span>{{ formData.planConfiguration.changePlanAmount }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="原临租审核总金额：" >
                                <span>{{ formData.planConfiguration.tempLeaseAuditAmount }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="变更后临租审核总金额：" >
                                <span>{{ formData.planConfiguration.changeTempLeaseAuditAmount }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="机构：" >
                                <span>{{ formData.planConfiguration.orgName }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="状态：" prop="state">
                            <span>{{ statusLable(formData.planConfiguration.state) }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-form-item  label="备注：" prop="remarks">
                        <el-input type="textarea" v-model="formData.planConfiguration.remarks"></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="本位币：">
                            <span>{{ formData.planConfiguration.baseCurName }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="人民币汇率：">
                            <span>{{formData.planConfiguration.rmbRate}}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                   <el-col :span="12">
                        <el-form-item label="本位币汇率：">
                            <span>{{ formData.planConfiguration.baseCurRate }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="变更期数：" >
                                <span>{{ formData.planConfiguration.number }}</span>
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="12">
                        <el-form-item label="计划金额（本位币）：">
                            <span>{{ formData.planConfiguration.baseCurPlanAmount }}</span>
                        </el-form-item>
                    </el-col> -->
                </el-row>
            </el-form>
        </div>
        <div class="buttons">
            <el-button
                type="primary"
                size="small"
                class="btn-blue"
                @click="preserve"
                v-debounce
                >保存</el-button
            >
            <el-button size="small" @click="handleClose"  v-debounce>取消</el-button>
        </div>
    </div>
</template>

<script>
import { mapState } from 'vuex'
import '@/utils/jquery.scrollTo.min'
import request from '@/api/equip/equipPlan.js'
// import { formatDate } from '@/utils/common.js'
export default {
    data () {
        return {
            formData: {
                //配置计划基础信息
                planConfiguration: {
                    'auditTime': '',
                    'auditor': '',
                    'auditorId': '',
                    'baseCurId': '',
                    'baseCurName': '',
                    'baseCurPlanAmount': null,
                    'baseCurRate': null,
                    'billDate': '',
                    'billId': '',
                    'billNo': '',
                    'changeBillId': '',
                    'changeBillNo': '',
                    'changeLongPlanAmount': null,
                    'changePlanAmount': 0,
                    'changeState': '',
                    'changeTempLeaseAmount': null,
                    'changeTempLeaseAuditAmount': null,
                    'currency': '',
                    'currencyId': '',
                    'founderId': '',
                    'founderName': '',
                    'longPlanAmount': null,
                    'modifier': '',
                    'modifierId': '',
                    'nullifyCreated': '',
                    'nullifyCreator': '',
                    'nullifyCreatorId': '',
                    'nullifyDesciption': '',
                    'nullifyReason': '',
                    'number': 0,
                    'orgId': '',
                    'orgName': '',
                    'planAmount': null,
                    'recorder': '',
                    'recorderId': '',
                    'remarks': '',
                    'rmbId': '',
                    'rmbName': '',
                    'rmbRate': null,
                    'rmbSumTempLeaseAmount': null,
                    'state': '',
                    'tempLeaseAmount': null,
                    'tempLeaseAuditAmount': null,
                    'version': null,
                    'workId': ''
                }
            },
            rules: {
                changeTempLeaseAmount: [
                    { required: true, message: '请输入变更后临租总金额', trigger: 'blur' },
                ],
            },
            billid: this.$route.query.billid,
        }
    },
    computed: {
        ...mapState({
            userInfo: state => state.userInfo,
            currencyForm: state => state.equip.equipData.currencyForm//币种
        }),
        //状态
        statusLable () {
            return param=> {
                const state =  this.$store.state.equip.equipData.state
                const obj = state.find(x=>+x.value === param)
                return (obj ?  obj.label :  '')
            }
        },
    },
    components: {
    },
    created () {
        this.userId = localStorage.getItem('userId')
        this.getInfo()
    },
    mounted () {

    },
    methods: {
        getInfo () { //默认获取数据
            const date = new Date()
            const params = {
                planId: this.billid,
                userId: this.userId
            }
            request.getInitConfigBaseInfo(params).then(res=>{
                this.formData.planConfiguration = res.planConfiguration
                this.formData.planConfiguration.billDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
                this.formData.planConfiguration.state = 0
                this.formData.planConfiguration.changeTempLeaseAmount = res.planConfiguration.tempLeaseAuditAmount
                this.formData.planConfiguration.changeTempLeaseAuditAmount = this.formData.planConfiguration.changeTempLeaseAmount
                this.formData.planConfiguration.changePlanAmount = 0
                this.formData.planConfiguration.changeBillId = this.billid
            })
        },
        //保存
        preserve () {
            this.$refs.form.validate(valid => {
                if (valid) {
                    request.baseInfoChangeAdd(this.formData.planConfiguration).then(res=>{
                        this.clientPop('info', '保存成功!是否进行下一步操作？', ()=>{
                            this.$router.push({
                                path: '/configPlanListChangeEdit',
                                query: {
                                    billid: res,
                                    name: 'planDetail'
                                }
                            })
                        },
                        null,
                        this.handleClose
                        )
                    })
                } else {
                    return false
                }
            })
        },
        //返回历史列表
        handleHistory () {
            this.$router.push({
                path: '/configPlanListShow',
                query: {
                    billid: this.billid,
                    name: 'changeHistory'
                }
            })
        },
        handleClose () {
            this.$router.replace('/configPlanList')
        },

    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.form {
    margin-top: 10px;
}
.e-form {
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}
</style>
